package com.central.user.util;

import org.apache.http.HttpEntity;

import java.util.HashMap;
import java.util.Map;
public class SmsUtil {
    private static String url;
    private static String corpId;
    private static String passWord;
    //    private static String encode;
    static {
        url = "https://mb345.com/ws/BatchSend2.aspx";
        corpId = "LKSDK0005795";
        passWord = "zh9527@";
//        encode = "";
    }

    public static String sendSms(String phoneNum, String smsContent, String sendTime) {
        Map<String, String> header = new HashMap<>(1);
        Map<String, String> param = new HashMap<>(1);
        param.put("CorpID", corpId);
        param.put("Pwd", passWord);
        param.put("Mobile", phoneNum);
        param.put("Content", smsContent);
        param.put("SendTime", sendTime);
        param.put("Cell","");
        HttpEntity entity = null;
        String result = "0";
        try {
            result = HttpsUtil.post(url, header, param, entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static String ErrorStr(String n){
        String returnStr = "";
        switch (n) {
            case "-1":
                returnStr = "账号未注册";
                break;
            case "-2":
                returnStr = "网络访问超时，请稍后再试";
                break;
            case "-3":
                returnStr = "帐号或密码错误";
                break;
            case "-4":
                returnStr = "只支持单发";
                break;
            case "-5":
                returnStr = "余额不足，请充值";
                break;
            case "-6":
                returnStr = "定时发送时间不是有效的时间格式";
                break;
            case "-7":
                returnStr = "提交信息末尾未签名，请添加中文的企业签名【 】或未采用gb2312编码";
                break;
            case "-8":
                returnStr = "发送内容需在1到300字之间";
                break;
            case "-9":
                returnStr = "发送号码为空";
                break;
            case "-10":
                returnStr = "定时时间不能小于系统当前时间";
                break;
            case "-11":
                returnStr = "屏蔽手机号码";
                break;
            case "-100":
                returnStr = "限制IP访问";
                break;
            default:
                break;
        }
        return returnStr;
    }

    public static String getVerifyCode(int num) {
        StringBuffer sb = new StringBuffer();
        sb.append((int) (Math.pow(10, num) * Math.random()));
        for (int i = sb.length(); i < num; i++) {

            sb.insert(0,0);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        SmsUtil.sendSms("17313181553",
                "您的验证码是：" + SmsUtil.getVerifyCode(6) + " 验证码有效时间2分钟，请勿泄露给其他人。【宝石大乱斗】",null);
    }
}
